ALTER TABLE ColorIndex
ALTER COLUMN Color VARCHAR(50) NOT NULL
GO

UPDATE ColorIndex SET Color = 'No Data', Red = 150, Green = 150, Blue = 150 WHERE ID = 0
UPDATE ColorIndex SET Color = 'Load Current', Red = 255, Green = 0, Blue = 0 WHERE ID = 1
UPDATE ColorIndex SET Color = 'Heavy Fault Current', Red = 0, Green = 0, Blue = 255 WHERE ID = 2
UPDATE ColorIndex SET Color = 'Light Fault Current', Red = 110, Green = 150, Blue = 250 WHERE ID = 3
UPDATE ColorIndex SET Color = 'Trip', Red = 0, Green = 102, Blue = 0 WHERE ID = 4
UPDATE ColorIndex SET Color = 'Open', Red = 0, Green = 255, Blue = 0 WHERE ID = 5
UPDATE ColorIndex SET Color = 'Good Voltage', Red = 200, Green = 0, Blue = 0 WHERE ID = 6
UPDATE ColorIndex SET Color = 'Voltage Sag', Red = 255, Green = 170, Blue = 100 WHERE ID = 7
UPDATE ColorIndex SET Color = 'Loss of Source', Red = 0, Green = 0, Blue = 0 WHERE ID = 9
DELETE FROM ColorIndex WHERE ID = 8 OR ID NOT BETWEEN 0 AND 9
DBCC CHECKIDENT(ColorIndex, RESEED, 9)
GO

CREATE NONCLUSTERED INDEX IX_SOEIncident_SOEID
ON SOEIncident(SOEID ASC)
GO

CREATE NONCLUSTERED INDEX IX_SOEIncident_IncidentID
ON SOEIncident(IncidentID ASC)
GO

CREATE TABLE SOELog
(
    ID INT IDENTITY(1, 1) NOT NULL PRIMARY KEY,
    EventID INT NOT NULL REFERENCES Event(ID),
    ColorIndexID INT NOT NULL REFERENCES ColorIndex(ID),
    Circuit VARCHAR(200) NOT NULL,
    DeviceName VARCHAR(200) NOT NULL,
    ChannelName VARCHAR(200) NOT NULL,
    SOETime DATETIME2 NOT NULL,
    SystemVoltage VARCHAR(20) NOT NULL,
    MeasurementNumber INT NOT NULL,
    MeasurementSampleNumber INT NOT NULL,
    MeasurementTime DATETIME2 NOT NULL,
    MeasurementValue FLOAT NOT NULL,
    MeasurementColor VARCHAR(20) NOT NULL,
    PlotFileName VARCHAR(MAX) NOT NULL
)
GO

CREATE NONCLUSTERED INDEX IX_SOELog_EventID
ON SOELog(EventID ASC)
GO